define(['jquery', 'bootstrap', 'backend', 'table', 'form','cookie'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'aps/dakalog/index',
                    add_url: 'aps/dakalog/add',
                    edit_url: 'aps/dakalog/edit',
                    del_url: 'aps/dakalog/del',
                    multi_url: 'aps/dakalog/multi',
                    table: 'aps_dakalog',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                showToggle: false,
                showExport: false,
                searchFormVisible: true,
                columns: [
                    [
                        //{checkbox: true},
                        {field: 'id', title: __('Id'), operate:false},
                        //{field: 'planlog_id', title: __('Planlog_id')},
                        //{field: 'procedurestate_id', title: __('Procedurestate_id')},
                        //{field: 'md5', title: __('Md5')},
                        {field: 'name', title: __('Name')},
                        {field: 'productnumber', title: __('Productnumber')},
                        {field: 'num', title: __('產量'), operate:false},
                        //{field: 'productname', title: __('Productname')},
                        //{field: 'guige', title: __('Guige')},
                        //{field: 'productmark', title: __('Productmark')},
                        //{field: 'gongxu', title: __('Gongxu')},
                        {field: 'procedurecode', title: __('Procedurecode')},
                        {field: 'procedurename', title: __('Procedurename'), operate:false},
                        //{field: 'productlinecode', title: __('Productlinecode'), operate:false},
                        //{field: 'productlinename', title: __('Productlinename'), operate:false},
                        //{field: 'machinecode', title: __('Machinecode')},
                        //{field: 'machinename', title: __('Machinename')},
                        {field: 'excutetype', title: __('Excutetype'), operate:false},
                        {field: 'excutetime', title: __('Excutetime'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'totalnumber', title: __('Totalnumber'), operate:false},
                        //{field: 'unitouput', title: __('Unitouput')},
                        //{field: 'loginnumber', title: __('Loginnumber')},
                        {field: 'loginname', title: __('Loginname'), operate:false},
                        //{field: 'item', title: __('Item')},
                        //{field: 'scrapquantity', title: __('Scrapquantity')},
                        //{field: 'shortquantity', title: __('Shortquantity')},
                        //{field: 'excessquantity', title: __('Excessquantity')},
                        //{field: 'repeatquantity', title: __('Repeatquantity')},
                        //{field: 'cancelno', title: __('Cancelno')},
                        //{field: 'translatenumber', title: __('Translatenumber')},
                        //{field: 'translateserialnumber', title: __('Translateserialnumber')},
                        //{field: 'workreportnumbers', title: __('Workreportnumbers')},
                        //{field: 'workreportserialnumber', title: __('Workreportserialnumber')},
                        //{field: 'packagenumber', title: __('Packagenumber')},
                        //{field: 'staffnumber', title: __('Staffnumber')},
                        //{field: 'staffname', title: __('Staffname')},
                        //{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.id', title: __('Planlog.id')},
                        //{field: 'planlog.workorder_id', title: __('Planlog.workorder_id')},
                        //{field: 'planlog.workorder_finishdate', title: __('Planlog.workorder_finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure1_id', title: __('Planlog.procedure1_id')},
                        //{field: 'planlog.procedure2_id', title: __('Planlog.procedure2_id')},
                        //{field: 'planlog.procedure3_id', title: __('Planlog.procedure3_id')},
                        //{field: 'planlog.procedure4_id', title: __('Planlog.procedure4_id')},
                        //{field: 'planlog.procedure5_id', title: __('Planlog.procedure5_id')},
                        //{field: 'planlog.procedure6_id', title: __('Planlog.procedure6_id')},
                        //{field: 'planlog.procedure7_id', title: __('Planlog.procedure7_id')},
                        //{field: 'planlog.procedure8_id', title: __('Planlog.procedure8_id')},
                        //{field: 'planlog.procedure1_man_id', title: __('Planlog.procedure1_man_id')},
                        //{field: 'planlog.procedure2_man_id', title: __('Planlog.procedure2_man_id')},
                        //{field: 'planlog.procedure3_man_id', title: __('Planlog.procedure3_man_id')},
                        //{field: 'planlog.procedure4_man_id', title: __('Planlog.procedure4_man_id')},
                        //{field: 'planlog.procedure5_man_id', title: __('Planlog.procedure5_man_id')},
                        //{field: 'planlog.procedure6_man_id', title: __('Planlog.procedure6_man_id')},
                        //{field: 'planlog.procedure7_man_id', title: __('Planlog.procedure7_man_id')},
                        //{field: 'planlog.procedure8_man_id', title: __('Planlog.procedure8_man_id')},
                        //{field: 'planlog.procedure1_finishdate', title: __('Planlog.procedure1_finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure2_finishdate', title: __('Planlog.procedure2_finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure3_finishdate', title: __('Planlog.procedure3_finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure4_finishdate', title: __('Planlog.procedure4_finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure5_finishdate', title: __('Planlog.procedure5_finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure6_finishdate', title: __('Planlog.procedure6_finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure7_finishdate', title: __('Planlog.procedure7_finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure8_finishdate', title: __('Planlog.procedure8_finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure1_startdate', title: __('Planlog.procedure1_startdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure2_startdate', title: __('Planlog.procedure2_startdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure3_startdate', title: __('Planlog.procedure3_startdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure4_startdate', title: __('Planlog.procedure4_startdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure5_startdate', title: __('Planlog.procedure5_startdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure6_startdate', title: __('Planlog.procedure6_startdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure7_startdate', title: __('Planlog.procedure7_startdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure8_startdate', title: __('Planlog.procedure8_startdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure1_manhours', title: __('Planlog.procedure1_manhours'), operate:'BETWEEN'},
                        //{field: 'planlog.procedure2_manhours', title: __('Planlog.procedure2_manhours'), operate:'BETWEEN'},
                        //{field: 'planlog.procedure3_manhours', title: __('Planlog.procedure3_manhours'), operate:'BETWEEN'},
                        //{field: 'planlog.procedure4_manhours', title: __('Planlog.procedure4_manhours'), operate:'BETWEEN'},
                        //{field: 'planlog.procedure5_manhours', title: __('Planlog.procedure5_manhours'), operate:'BETWEEN'},
                        //{field: 'planlog.procedure6_manhours', title: __('Planlog.procedure6_manhours'), operate:'BETWEEN'},
                        //{field: 'planlog.procedure7_manhours', title: __('Planlog.procedure7_manhours'), operate:'BETWEEN'},
                        //{field: 'planlog.procedure8_manhours', title: __('Planlog.procedure8_manhours'), operate:'BETWEEN'},
                        //{field: 'planlog.finishnum', title: __('Planlog.finishnum')},
                        //{field: 'planlog.maxnum', title: __('Planlog.maxnum')},
                        //{field: 'planlog.sjwg', title: __('Planlog.sjwg'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.state', title: __('Planlog.state')},
                        //{field: 'planlog.jhwg', title: __('Planlog.jhwg'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.update_time', title: __('Planlog.update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'planlog.create_time', title: __('Planlog.create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'planlog.procedure9_id', title: __('Planlog.procedure9_id')},
                        //{field: 'planlog.procedure10_id', title: __('Planlog.procedure10_id')},
                        //{field: 'planlog.procedure11_id', title: __('Planlog.procedure11_id')},
                        //{field: 'planlog.procedure12_id', title: __('Planlog.procedure12_id')},
                        //{field: 'planlog.procedure9_man_id', title: __('Planlog.procedure9_man_id')},
                        //{field: 'planlog.procedure10_man_id', title: __('Planlog.procedure10_man_id')},
                        //{field: 'planlog.procedure11_man_id', title: __('Planlog.procedure11_man_id')},
                        //{field: 'planlog.procedure12_man_id', title: __('Planlog.procedure12_man_id')},
                        //{field: 'planlog.procedure9_startdate', title: __('Planlog.procedure9_startdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure10_startdate', title: __('Planlog.procedure10_startdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure11_startdate', title: __('Planlog.procedure11_startdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure12_startdate', title: __('Planlog.procedure12_startdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure9_finishdate', title: __('Planlog.procedure9_finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure10_finishdate', title: __('Planlog.procedure10_finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure11_finishdate', title: __('Planlog.procedure11_finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure12_finishdate', title: __('Planlog.procedure12_finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure9_manhours', title: __('Planlog.procedure9_manhours'), operate:'BETWEEN'},
                        //{field: 'planlog.procedure10_manhours', title: __('Planlog.procedure10_manhours'), operate:'BETWEEN'},
                        //{field: 'planlog.procedure11_manhours', title: __('Planlog.procedure11_manhours'), operate:'BETWEEN'},
                        //{field: 'planlog.procedure12_manhours', title: __('Planlog.procedure12_manhours'), operate:'BETWEEN'},
                        //{field: 'planlog.procedure1_preparedate', title: __('Planlog.procedure1_preparedate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure2_preparedate', title: __('Planlog.procedure2_preparedate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure3_preparedate', title: __('Planlog.procedure3_preparedate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure4_preparedate', title: __('Planlog.procedure4_preparedate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure5_preparedate', title: __('Planlog.procedure5_preparedate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure6_preparedate', title: __('Planlog.procedure6_preparedate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure7_preparedate', title: __('Planlog.procedure7_preparedate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure8_preparedate', title: __('Planlog.procedure8_preparedate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure9_preparedate', title: __('Planlog.procedure9_preparedate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure10_preparedate', title: __('Planlog.procedure10_preparedate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure11_preparedate', title: __('Planlog.procedure11_preparedate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.procedure12_preparedate', title: __('Planlog.procedure12_preparedate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.overtime_hours', title: __('Planlog.overtime_hours'), operate:'BETWEEN'},
                        //{field: 'planlog.yjkg', title: __('Planlog.yjkg'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'planlog.switch', title: __('Planlog.switch'), formatter: Table.api.formatter.toggle},
                        //{field: 'planlog.procedure1_mannum', title: __('Planlog.procedure1_mannum')},
                        //{field: 'planlog.procedure2_mannum', title: __('Planlog.procedure2_mannum')},
                        //{field: 'planlog.procedure3_mannum', title: __('Planlog.procedure3_mannum')},
                        //{field: 'planlog.procedure4_mannum', title: __('Planlog.procedure4_mannum')},
                        //{field: 'planlog.procedure5_mannum', title: __('Planlog.procedure5_mannum')},
                        //{field: 'planlog.procedure6_mannum', title: __('Planlog.procedure6_mannum')},
                        //{field: 'planlog.procedure7_mannum', title: __('Planlog.procedure7_mannum')},
                        //{field: 'planlog.procedure8_mannum', title: __('Planlog.procedure8_mannum')},
                        //{field: 'planlog.procedure9_mannum', title: __('Planlog.procedure9_mannum')},
                        //{field: 'planlog.procedure10_mannum', title: __('Planlog.procedure10_mannum')},
                        //{field: 'planlog.procedure11_mannum', title: __('Planlog.procedure11_mannum')},
                        //{field: 'planlog.procedure12_mannum', title: __('Planlog.procedure12_mannum')},
                        //{field: 'procedurestate.id', title: __('Procedurestate.id')},
                        //{field: 'procedurestate.planlog_id', title: __('Procedurestate.planlog_id')},
                        //{field: 'procedurestate.procedure_id', title: __('Procedurestate.procedure_id')},
                        //{field: 'procedurestate.order', title: __('Procedurestate.order')},
                        //{field: 'procedurestate.state', title: __('Procedurestate.state')},
                        //{field: 'procedurestate.statename', title: __('Procedurestate.statename')},
                        //{field: 'procedurestate.startdate', title: __('Procedurestate.startdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'procedurestate.enddate', title: __('Procedurestate.enddate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'procedurestate.createtime', title: __('Procedurestate.createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'procedurestate.updatetime', title: __('Procedurestate.updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 选择隐藏字段事件，使用cookie存入
            table.on('column-switch.bs.table', function (e, json) {
                    var myColumns=[];
                    $.each(table.bootstrapTable('getHiddenColumns'), function(i, item) {
                         myColumns.push(item.field);
                    });
                    $.cookie('fa_aps_dakalog', JSON.stringify(myColumns), { expires: 365, path: '/'});
             });
             if($.cookie('fa_aps_dakalog')){
                //读取cookie隐藏字段
                $.each(JSON.parse($.cookie('fa_aps_dakalog')), function(i, item) {
                  table.bootstrapTable('hideColumn', item);
                });
             }

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});